package com.cdyx.outsideprescription.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cdyx.outsideprescription.dto.Icd_10Dto;
import com.cdyx.outsideprescription.dto.YPxxDto;
import com.cdyx.outsideprescription.entity.TbDicCf;
import com.cdyx.outsideprescription.service.ITbDicCfService;
import com.cdyx.outsideprescription.util.AppResponse;
import com.cdyx.outsideprescription.util.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jiang dongqiong
 * @since 2021-12-17
 */
@RestController
@RequestMapping("/dic")
@Api("获取字典数据")
public class DicCfController {
    @Qualifier("dicCfServiceImpl")
    @Autowired
    public ITbDicCfService tbDicCfService;

    @PostMapping("/getIcd10")
    @ApiOperation("获取诊断信息")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "data",//参数名字
                    value = "这是一个添加",//参数的描述
                    required = true,//是否是必须要传的参数，true是
                    paramType = "body",//参数类型 body 代表json
                    example = "{\"limit\":10,\"current\":1,\"condition\":\"aa\"}"
            )
    )
    public AppResponse getIcd10(@RequestBody() Map<String,Object> data){
        String condition = data.getOrDefault("condition", "").toString();
        int limit = Integer.parseInt(data.getOrDefault("limit", "10").toString());
        int current = Integer.parseInt(data.getOrDefault("current", "1").toString());
        QueryWrapper<Icd_10Dto> queryWrapper=new QueryWrapper<>();
       queryWrapper.like(!condition.isEmpty(),"CCNAME",condition)
               .or().like(!condition.isEmpty(),"CCODE10",condition);
        Page<Icd_10Dto> page=new Page<>(current,limit,true);
        IPage<Icd_10Dto> iPage= tbDicCfService.getIcd10(page,queryWrapper);
        Map<String, Long> pageInfo = PageInfo.getPageInfo(iPage);
        List<Icd_10Dto> icd10DtoList = iPage.getRecords();
        Map<String,Object> icd10=new HashMap<>();
        icd10.put("icd10",icd10DtoList);
        icd10.put("pageInfo",pageInfo);
        return AppResponse.ok(icd10);
    }
    @PostMapping("getDic")
    @ApiOperation("所有的字典数据")
   public AppResponse getDic(){
        List<TbDicCf> dicCfs=tbDicCfService.list();
        return AppResponse.ok(dicCfs);
    }
    @ApiOperation("获取药品信息")
    @PostMapping("/getYPxx")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "data",//参数名字
                    value = "这是一个添加",//参数的描述
                    required = true,//是否是必须要传的参数，true是
                    paramType = "body",//参数类型 body 代表json
                    example = "{\"limit\":10,\"current\":1,\"condition\":\"aa\"}"
            )
    )
    public AppResponse getYPxx(@RequestBody Map<String,Object> data){
        String condition = data.getOrDefault("condition", "").toString();
        int limit = Integer.parseInt(data.getOrDefault("limit", "10").toString());
        int current = Integer.parseInt(data.getOrDefault("current", "1").toString());
        String type = data.getOrDefault("type", "").toString();
        QueryWrapper<YPxxDto> queryWrapper=new QueryWrapper<>();
        queryWrapper
                .like(!condition.isEmpty(),"hospitalMedicineCode",condition).or()
                .like(!condition.isEmpty(),"prodname",condition).or().like(!condition.isEmpty(),"PYM",condition);
        Page<YPxxDto> page=new Page<>(current,limit,true);
        IPage<YPxxDto> iPage= tbDicCfService.selectYPxx(page,queryWrapper,type);
        Map<String, Long> pageInfo = PageInfo.getPageInfo(iPage);
        List<YPxxDto> records = iPage.getRecords();
        Map<String,Object> ypxx=new HashMap<>();
        ypxx.put("ypxx",records);
        ypxx.put("pageInfo",pageInfo);
        return AppResponse.ok(ypxx);

    }

    @PostMapping("getYpbz")
    @ApiOperation("药品备注")
    public AppResponse getYpbz(){
        List<Map<String,Object>> yPbz=tbDicCfService.getYPbz();
        return AppResponse.ok(yPbz);
    }

    @PostMapping("getCfBZ")
    @ApiOperation("药品备注")
    public AppResponse getCfBZ(){
        List<Map<String,Object>> CFBZ=tbDicCfService.getCfBZ();
        return AppResponse.ok(CFBZ);
    }
    @PostMapping("getYYTJ")
    public AppResponse getYYtj(){
       List<Map<String,String>> yytj= tbDicCfService.getYYtj();
       return AppResponse.ok(yytj);
    }
    @PostMapping("getYPYC")
    @ApiOperation("使用频次")
    public AppResponse getYPyc(){
        List<Map<String,String>> ypyc=tbDicCfService.getypYC();
        return AppResponse.ok(ypyc);
    }
    @PostMapping("getZCYxx")
    public AppResponse getZCYxx(){
       List<Map<String,String>> cyx= tbDicCfService.getZcyxx();
       return AppResponse.ok(cyx);
    }
}
